package work.hashmap;

import java.util.*;

public class Problem128 {
    public int longestConsecutive(int[] nums) {
        Set<Integer> num_set = new HashSet<Integer>();
        for (int num : nums) {
            num_set.add(num);
        }
        int longestStreak = 0;
        for (int num : num_set) {
            if (!num_set.contains(num - 1)) {
                int currentNum = num;
                int currentStreak = 1;
                while (num_set.contains(currentNum + 1)) {
                    currentNum += 1;
                    currentStreak += 1;
                }
                longestStreak = Math.max(longestStreak, currentStreak);
            }
        }
        return longestStreak;
    }

    ;

    public static void main(String[] args) {
        Problem128 problem128 = new Problem128();
        int[] arr1 = {100, 4, 200, 1, 3, 2};
        problem128.longestConsecutive(arr1);
    }


}
